window.onload = function (){
    const login = Vue.createApp({
        data(){
            return {
                telephone:"",
                pwd:"",
                isShow : false,
            }
        },
        methods:{
            isRightUsnAndPwd: function () {
                const xhr = new XMLHttpRequest();
                xhr.open("POST", "http://localhost:8080/LogInServlet?tel=" + this.telephone + "&pwd=" + this.pwd);
                xhr.send();
                xhr.onreadystatechange = function () {
                    if (xhr.readyState === 4) {
                        if (xhr.status >= 200 && xhr.status < 300) {
                            if(xhr.response === 'true'){
                                window.location.href="index.html";
                            }
                            else {
                                login.isShow = true;
                            }
                        }
                    }
                }
            },
            toRegister(){
                window.location.href = "register.html";
            }
        },
        created : function (){
            const xhr = new XMLHttpRequest();
            xhr.open("POST", "http://localhost:8080/LogInServlet");
            xhr.send();
            xhr.onreadystatechange = function () {
                if (xhr.readyState === 4) {
                    if (xhr.status >= 200 && xhr.status < 300) {
                        if(xhr.response === 'true'){
                            window.location.href="index.html";
                        }
                    }
                }
            }
        },
        template:"#login-table"
    }).mount("#app");
}
